<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>递归调用</title>
</head>
<body>
        <script>
                function factorial(n) {       
                  if (n == 1) {
                    return 1;                  
                  }
                  return n * factorial(n - 1);
                }
                var n = prompt('求n的阶乘\n n是大于等于1的正整数，如2表示求2!。');
                n = parseInt(n);
                if (isNaN(n)) {
                  console.log('输入的n值不合法');
                } else {
                  console.log(n + '的阶乘为：' + factorial(n));
                }
              </script>
        <p><a href="第四章.html">返回上一级</a></p>
</body>
</html>